package cn.rkylin.oms.aftersale.resend.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.github.pagehelper.PageInfo;

import cn.rkylin.core.IDataBaseFactory;
import cn.rkylin.oms.aftersale.resend.dao.IAfterSaleResendDAO;
import cn.rkylin.oms.aftersale.resend.domain.AfterSaleResend;
import cn.rkylin.oms.aftersale.resend.vo.ResendVO;

/**
 * 类名:AfterSaleResendDAOImpl <br/>
 * 作用: 系统补发单数据访问类. <br/>
 * 创建原因: 系统补发单的数据访问. <br/>
 * 创建时间: 2017年11月7日 13:30:00 <br/>
 * 
 * @author liPeng
 * @version v1.0
 */
@Repository(value = "afterSaleResendDAO")
public class AfterSaleResendDAOImpl implements IAfterSaleResendDAO {
    @Autowired
    IDataBaseFactory dao;

    private static final String STATEMENT_PAGE_SELECT_BY_CONDITION = "pageSelectResendByCondition";
    private static final String STATEMENT_PAGE_SELECT_BY_PRIMARYKEY = "selectByPrimaryKeyResend";
    private static final String STATEMENT_UPDATE = "updateByPrimaryKeySelectiveResend";
    private static final String STMT_INSERT_SELECTIVE_RESEND = "insertSelectiveResend";
    private static final String SELECT_ONGOING_AFTERSALERESEND = "selectOnGoingAftersaleResend";

    /**
     * pageSelectByCondition:条件查询补发单列表
     */
    public PageInfo<ResendVO> pageSelectByCondition(int page, int length, ResendVO queryParamVO) throws Exception {
        PageInfo<ResendVO> returnObject = dao.find(page, length, STATEMENT_PAGE_SELECT_BY_CONDITION, queryParamVO);
        return returnObject;

    }

    /**
     * getResendListByCondition:根据查询条件查询补发单数据. <br/>
     */
    public List<ResendVO> seleteByCondition(ResendVO queryParamVO) throws Exception {
        return dao.findAllList(STATEMENT_PAGE_SELECT_BY_CONDITION, queryParamVO);
    }

    /**
     * selectByPrimaryKey：根据补发单ID获取补发单
     */
    public AfterSaleResend selectByPrimaryKey(String resendId) throws Exception {
        ResendVO resendVO = new ResendVO();
        resendVO.setResendId(resendId);
        return dao.findOne(STATEMENT_PAGE_SELECT_BY_PRIMARYKEY, resendVO);
    }

    /**
     * 修改补发单
     */
    public int updateByPrimaryKeySelective(AfterSaleResend record) throws Exception {
        return dao.update(STATEMENT_UPDATE, record);
    }

    /**
     * 保存补发单
     * 
     * @param resendVO
     * @throws Exception
     */
    public int insert(ResendVO resend) throws Exception {
        return dao.insert(STMT_INSERT_SELECTIVE_RESEND, resend);

    }

    /**
     * selectDetailByPrimaryKey：：根据补发单id获取补发单所有相关数据
     */
    public ResendVO selectDetailByPrimaryKey(String resendId) throws Exception {
        ResendVO resendVO = new ResendVO();
        resendVO.setResendId(resendId);
        return dao.findOne(STATEMENT_PAGE_SELECT_BY_PRIMARYKEY, resendVO);
    }

    /**
     * 通过来源ID获取未取消补发单信息
     * @param sourceId
     * @return
     * @throws Exception
     */
    public List<AfterSaleResend> selectResendBySourceID(String sourceId) throws Exception {
        return dao.findList("selectResendBySourceID", sourceId);
    }

    /**
     * 通过id获取补发单信息
     * @param resendId
     * @return
     * @throws Exception
     */
    public AfterSaleResend selectResendByResendID(String resendId) throws Exception {
        return dao.findOne("selectResendByResendID", resendId);
    }

    @Override
    public ResendVO getCount(ResendVO vo) throws Exception {
        return dao.findOne("selectResendCound", vo);
    }
    
    @Override
    public int getUnGoingCount(Map<String, String> paramMap) throws Exception {
        return dao.findOne(SELECT_ONGOING_AFTERSALERESEND, paramMap);
    }

}
